<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>pattern_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_dom_pattern_pattern_test.js.html">pattern_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2007 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.dom.patternTest&#39;);
<a name="line16"></a>goog.setTestOnly(&#39;goog.dom.patternTest&#39;);
<a name="line17"></a>
<a name="line18"></a>goog.require(&#39;goog.dom&#39;);
<a name="line19"></a>goog.require(&#39;goog.dom.NodeType&#39;);
<a name="line20"></a>goog.require(&#39;goog.dom.TagWalkType&#39;);
<a name="line21"></a>goog.require(&#39;goog.dom.pattern.AllChildren&#39;);
<a name="line22"></a>goog.require(&#39;goog.dom.pattern.ChildMatches&#39;);
<a name="line23"></a>goog.require(&#39;goog.dom.pattern.EndTag&#39;);
<a name="line24"></a>goog.require(&#39;goog.dom.pattern.FullTag&#39;);
<a name="line25"></a>goog.require(&#39;goog.dom.pattern.MatchType&#39;);
<a name="line26"></a>goog.require(&#39;goog.dom.pattern.NodeType&#39;);
<a name="line27"></a>goog.require(&#39;goog.dom.pattern.Repeat&#39;);
<a name="line28"></a>goog.require(&#39;goog.dom.pattern.Sequence&#39;);
<a name="line29"></a>goog.require(&#39;goog.dom.pattern.StartTag&#39;);
<a name="line30"></a>goog.require(&#39;goog.dom.pattern.Text&#39;);
<a name="line31"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line32"></a>
<a name="line33"></a>// TODO(robbyw): write a test that checks if backtracking works in Sequence
<a name="line34"></a>
<a name="line35"></a>function testStartTag() {
<a name="line36"></a>  var pattern = new goog.dom.pattern.StartTag(&#39;DIV&#39;);
<a name="line37"></a>  assertEquals(
<a name="line38"></a>      &#39;StartTag(div) should match div&#39;,
<a name="line39"></a>      goog.dom.pattern.MatchType.MATCH,
<a name="line40"></a>      pattern.matchToken(
<a name="line41"></a>          goog.dom.getElement(&#39;div1&#39;),
<a name="line42"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line43"></a>  assertEquals(
<a name="line44"></a>      &#39;StartTag(div) should not match span&#39;,
<a name="line45"></a>      goog.dom.pattern.MatchType.NO_MATCH,
<a name="line46"></a>      pattern.matchToken(
<a name="line47"></a>          goog.dom.getElement(&#39;span1&#39;),
<a name="line48"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line49"></a>  assertEquals(
<a name="line50"></a>      &#39;StartTag(div) should not match /div&#39;,
<a name="line51"></a>      goog.dom.pattern.MatchType.NO_MATCH,
<a name="line52"></a>      pattern.matchToken(
<a name="line53"></a>          goog.dom.getElement(&#39;div1&#39;),
<a name="line54"></a>          goog.dom.TagWalkType.END_TAG));
<a name="line55"></a>}
<a name="line56"></a>
<a name="line57"></a>function testStartTagCase() {
<a name="line58"></a>  var pattern = new goog.dom.pattern.StartTag(&#39;diV&#39;);
<a name="line59"></a>  assertEquals(
<a name="line60"></a>      &#39;StartTag(diV) should match div&#39;,
<a name="line61"></a>      goog.dom.pattern.MatchType.MATCH,
<a name="line62"></a>      pattern.matchToken(
<a name="line63"></a>          goog.dom.getElement(&#39;div1&#39;),
<a name="line64"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line65"></a>  assertEquals(
<a name="line66"></a>      &#39;StartTag(diV) should not match span&#39;,
<a name="line67"></a>      goog.dom.pattern.MatchType.NO_MATCH,
<a name="line68"></a>      pattern.matchToken(
<a name="line69"></a>          goog.dom.getElement(&#39;span1&#39;),
<a name="line70"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line71"></a>}
<a name="line72"></a>
<a name="line73"></a>function testStartTagRegex() {
<a name="line74"></a>  var pattern = new goog.dom.pattern.StartTag(/D/);
<a name="line75"></a>  assertEquals(
<a name="line76"></a>      &#39;StartTag(/D/) should match div&#39;,
<a name="line77"></a>      goog.dom.pattern.MatchType.MATCH,
<a name="line78"></a>      pattern.matchToken(
<a name="line79"></a>          goog.dom.getElement(&#39;div1&#39;),
<a name="line80"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line81"></a>  assertEquals(
<a name="line82"></a>      &#39;StartTag(/D/) should not match span&#39;,
<a name="line83"></a>      goog.dom.pattern.MatchType.NO_MATCH,
<a name="line84"></a>      pattern.matchToken(
<a name="line85"></a>          goog.dom.getElement(&#39;span1&#39;),
<a name="line86"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line87"></a>  assertEquals(
<a name="line88"></a>      &#39;StartTag(/D/) should not match /div&#39;,
<a name="line89"></a>      goog.dom.pattern.MatchType.NO_MATCH,
<a name="line90"></a>      pattern.matchToken(
<a name="line91"></a>          goog.dom.getElement(&#39;div1&#39;),
<a name="line92"></a>          goog.dom.TagWalkType.END_TAG));
<a name="line93"></a>}
<a name="line94"></a>
<a name="line95"></a>function testStartTagAttributes() {
<a name="line96"></a>  var pattern = new goog.dom.pattern.StartTag(&#39;DIV&#39;, {id: &#39;div1&#39;});
<a name="line97"></a>  assertEquals(
<a name="line98"></a>      &#39;StartTag(div,id:div1) should match div1&#39;,
<a name="line99"></a>      goog.dom.pattern.MatchType.MATCH,
<a name="line100"></a>      pattern.matchToken(
<a name="line101"></a>          goog.dom.getElement(&#39;div1&#39;),
<a name="line102"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line103"></a>  assertEquals(&#39;StartTag(div,id:div2) should not match div1&#39;,
<a name="line104"></a>      goog.dom.pattern.MatchType.NO_MATCH,
<a name="line105"></a>      pattern.matchToken(
<a name="line106"></a>          goog.dom.getElement(&#39;div2&#39;),
<a name="line107"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line108"></a>}
<a name="line109"></a>
<a name="line110"></a>function testStartTagStyle() {
<a name="line111"></a>  var pattern = new goog.dom.pattern.StartTag(&#39;SPAN&#39;, null, {color: &#39;red&#39;});
<a name="line112"></a>  assertEquals(
<a name="line113"></a>      &#39;StartTag(span,null,color:red) should match span1&#39;,
<a name="line114"></a>      goog.dom.pattern.MatchType.MATCH,
<a name="line115"></a>      pattern.matchToken(
<a name="line116"></a>          goog.dom.getElement(&#39;span1&#39;),
<a name="line117"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line118"></a>  assertEquals(
<a name="line119"></a>      &#39;StartTag(span,null,color:blue) should not match span1&#39;,
<a name="line120"></a>      goog.dom.pattern.MatchType.NO_MATCH,
<a name="line121"></a>      pattern.matchToken(
<a name="line122"></a>          goog.dom.getElement(&#39;span2&#39;),
<a name="line123"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line124"></a>}
<a name="line125"></a>
<a name="line126"></a>function testStartTagAttributeRegex() {
<a name="line127"></a>  var pattern = new goog.dom.pattern.StartTag(&#39;SPAN&#39;, {id: /span\d/});
<a name="line128"></a>  assertEquals(
<a name="line129"></a>      &#39;StartTag(span,id:/span\\d/) should match span1&#39;,
<a name="line130"></a>      goog.dom.pattern.MatchType.MATCH,
<a name="line131"></a>      pattern.matchToken(
<a name="line132"></a>          goog.dom.getElement(&#39;span1&#39;),
<a name="line133"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line134"></a>  assertEquals(
<a name="line135"></a>      &#39;StartTag(span,id:/span\\d/) should match span2&#39;,
<a name="line136"></a>      goog.dom.pattern.MatchType.MATCH,
<a name="line137"></a>      pattern.matchToken(
<a name="line138"></a>          goog.dom.getElement(&#39;span1&#39;),
<a name="line139"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line140"></a>}
<a name="line141"></a>
<a name="line142"></a>function testEndTag() {
<a name="line143"></a>  var pattern = new goog.dom.pattern.EndTag(&#39;DIV&#39;);
<a name="line144"></a>  assertEquals(
<a name="line145"></a>      &#39;EndTag should match div&#39;,
<a name="line146"></a>      goog.dom.pattern.MatchType.MATCH,
<a name="line147"></a>      pattern.matchToken(
<a name="line148"></a>          goog.dom.getElement(&#39;div1&#39;),
<a name="line149"></a>          goog.dom.TagWalkType.END_TAG));
<a name="line150"></a>}
<a name="line151"></a>
<a name="line152"></a>function testEndTagRegex() {
<a name="line153"></a>  var pattern = new goog.dom.pattern.EndTag(/D/);
<a name="line154"></a>  assertEquals(
<a name="line155"></a>      &#39;EndTag(/D/) should match /div&#39;,
<a name="line156"></a>      goog.dom.pattern.MatchType.MATCH,
<a name="line157"></a>      pattern.matchToken(
<a name="line158"></a>          goog.dom.getElement(&#39;div1&#39;),
<a name="line159"></a>          goog.dom.TagWalkType.END_TAG));
<a name="line160"></a>  assertEquals(
<a name="line161"></a>      &#39;EndTag(/D/) should not match /span&#39;,
<a name="line162"></a>      goog.dom.pattern.MatchType.NO_MATCH,
<a name="line163"></a>      pattern.matchToken(
<a name="line164"></a>          goog.dom.getElement(&#39;span1&#39;),
<a name="line165"></a>          goog.dom.TagWalkType.END_TAG));
<a name="line166"></a>  assertEquals(
<a name="line167"></a>      &#39;EndTag(/D/) should not match div&#39;,
<a name="line168"></a>      goog.dom.pattern.MatchType.NO_MATCH,
<a name="line169"></a>      pattern.matchToken(
<a name="line170"></a>          goog.dom.getElement(&#39;div1&#39;),
<a name="line171"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line172"></a>}
<a name="line173"></a>
<a name="line174"></a>function testChildMatches() {
<a name="line175"></a>  var pattern = new goog.dom.pattern.ChildMatches(
<a name="line176"></a>      new goog.dom.pattern.StartTag(&#39;DIV&#39;), 2);
<a name="line177"></a>
<a name="line178"></a>  assertEquals(
<a name="line179"></a>      &#39;ChildMatches should match div&#39;,
<a name="line180"></a>      goog.dom.pattern.MatchType.MATCHING,
<a name="line181"></a>      pattern.matchToken(
<a name="line182"></a>          goog.dom.getElement(&#39;div1&#39;),
<a name="line183"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line184"></a>  assertEquals(
<a name="line185"></a>      &#39;ChildMatches should match /div&#39;,
<a name="line186"></a>      goog.dom.pattern.MatchType.MATCHING,
<a name="line187"></a>      pattern.matchToken(
<a name="line188"></a>          goog.dom.getElement(&#39;div1&#39;),
<a name="line189"></a>          goog.dom.TagWalkType.END_TAG));
<a name="line190"></a>  assertEquals(
<a name="line191"></a>      &#39;ChildMatches should match div&#39;,
<a name="line192"></a>      goog.dom.pattern.MatchType.MATCHING,
<a name="line193"></a>      pattern.matchToken(
<a name="line194"></a>          goog.dom.getElement(&#39;div2&#39;),
<a name="line195"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line196"></a>  assertEquals(
<a name="line197"></a>      &#39;ChildMatches should match /div&#39;,
<a name="line198"></a>      goog.dom.pattern.MatchType.MATCHING,
<a name="line199"></a>      pattern.matchToken(
<a name="line200"></a>          goog.dom.getElement(&#39;div2&#39;),
<a name="line201"></a>          goog.dom.TagWalkType.END_TAG));
<a name="line202"></a>  assertEquals(
<a name="line203"></a>      &#39;ChildMatches should finish match at /body&#39;,
<a name="line204"></a>      goog.dom.pattern.MatchType.BACKTRACK_MATCH,
<a name="line205"></a>      pattern.matchToken(
<a name="line206"></a>          document.body,
<a name="line207"></a>          goog.dom.TagWalkType.END_TAG));
<a name="line208"></a>
<a name="line209"></a>  assertEquals(
<a name="line210"></a>      &#39;ChildMatches should match div&#39;,
<a name="line211"></a>      goog.dom.pattern.MatchType.MATCHING,
<a name="line212"></a>      pattern.matchToken(
<a name="line213"></a>          goog.dom.getElement(&#39;div2&#39;),
<a name="line214"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line215"></a>  assertEquals(
<a name="line216"></a>      &#39;ChildMatches should match /div&#39;,
<a name="line217"></a>      goog.dom.pattern.MatchType.MATCHING,
<a name="line218"></a>      pattern.matchToken(
<a name="line219"></a>          goog.dom.getElement(&#39;div2&#39;),
<a name="line220"></a>          goog.dom.TagWalkType.END_TAG));
<a name="line221"></a>  assertEquals(
<a name="line222"></a>      &#39;ChildMatches should fail to match at /body: not enough child matches&#39;,
<a name="line223"></a>      goog.dom.pattern.MatchType.NO_MATCH,
<a name="line224"></a>      pattern.matchToken(
<a name="line225"></a>          document.body,
<a name="line226"></a>          goog.dom.TagWalkType.END_TAG));
<a name="line227"></a>}
<a name="line228"></a>
<a name="line229"></a>function testFullTag() {
<a name="line230"></a>  var pattern = new goog.dom.pattern.FullTag(&#39;DIV&#39;);
<a name="line231"></a>  assertEquals(
<a name="line232"></a>      &#39;FullTag(div) should match div&#39;,
<a name="line233"></a>      goog.dom.pattern.MatchType.MATCHING,
<a name="line234"></a>      pattern.matchToken(
<a name="line235"></a>          goog.dom.getElement(&#39;div1&#39;),
<a name="line236"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line237"></a>  assertEquals(
<a name="line238"></a>      &#39;FullTag(div) should match /div&#39;,
<a name="line239"></a>      goog.dom.pattern.MatchType.MATCH,
<a name="line240"></a>      pattern.matchToken(
<a name="line241"></a>          goog.dom.getElement(&#39;div1&#39;),
<a name="line242"></a>          goog.dom.TagWalkType.END_TAG));
<a name="line243"></a>
<a name="line244"></a>  assertEquals(
<a name="line245"></a>      &#39;FullTag(div) should start match at div&#39;,
<a name="line246"></a>      goog.dom.pattern.MatchType.MATCHING,
<a name="line247"></a>      pattern.matchToken(
<a name="line248"></a>          goog.dom.getElement(&#39;div1&#39;),
<a name="line249"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line250"></a>  assertEquals(
<a name="line251"></a>      &#39;FullTag(div) should continue to match span&#39;,
<a name="line252"></a>      goog.dom.pattern.MatchType.MATCHING,
<a name="line253"></a>      pattern.matchToken(
<a name="line254"></a>          goog.dom.getElement(&#39;span1&#39;),
<a name="line255"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line256"></a>  assertEquals(
<a name="line257"></a>      &#39;FullTag(div) should continue to match /span&#39;,
<a name="line258"></a>      goog.dom.pattern.MatchType.MATCHING,
<a name="line259"></a>      pattern.matchToken(
<a name="line260"></a>          goog.dom.getElement(&#39;span1&#39;),
<a name="line261"></a>          goog.dom.TagWalkType.END_TAG));
<a name="line262"></a>  assertEquals(
<a name="line263"></a>      &#39;FullTag(div) should finish match at /div&#39;,
<a name="line264"></a>      goog.dom.pattern.MatchType.MATCH,
<a name="line265"></a>      pattern.matchToken(
<a name="line266"></a>          goog.dom.getElement(&#39;div1&#39;),
<a name="line267"></a>          goog.dom.TagWalkType.END_TAG));
<a name="line268"></a>}
<a name="line269"></a>
<a name="line270"></a>function testAllChildren() {
<a name="line271"></a>  var pattern = new goog.dom.pattern.AllChildren();
<a name="line272"></a>  assertEquals(
<a name="line273"></a>      &#39;AllChildren(div) should match div&#39;,
<a name="line274"></a>      goog.dom.pattern.MatchType.MATCHING,
<a name="line275"></a>      pattern.matchToken(
<a name="line276"></a>          goog.dom.getElement(&#39;div1&#39;),
<a name="line277"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line278"></a>  assertEquals(
<a name="line279"></a>      &#39;AllChildren(div) should match /div&#39;,
<a name="line280"></a>      goog.dom.pattern.MatchType.MATCHING,
<a name="line281"></a>      pattern.matchToken(
<a name="line282"></a>          goog.dom.getElement(&#39;div1&#39;),
<a name="line283"></a>          goog.dom.TagWalkType.END_TAG));
<a name="line284"></a>  assertEquals(
<a name="line285"></a>      &#39;AllChildren(div) should match at /body&#39;,
<a name="line286"></a>      goog.dom.pattern.MatchType.BACKTRACK_MATCH,
<a name="line287"></a>      pattern.matchToken(
<a name="line288"></a>          document.body,
<a name="line289"></a>          goog.dom.TagWalkType.END_TAG));
<a name="line290"></a>
<a name="line291"></a>  assertEquals(
<a name="line292"></a>      &#39;AllChildren(div) should start match at div&#39;,
<a name="line293"></a>      goog.dom.pattern.MatchType.MATCHING,
<a name="line294"></a>      pattern.matchToken(
<a name="line295"></a>          goog.dom.getElement(&#39;div1&#39;),
<a name="line296"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line297"></a>  assertEquals(
<a name="line298"></a>      &#39;AllChildren(div) should continue to match span&#39;,
<a name="line299"></a>      goog.dom.pattern.MatchType.MATCHING,
<a name="line300"></a>      pattern.matchToken(
<a name="line301"></a>          goog.dom.getElement(&#39;span1&#39;),
<a name="line302"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line303"></a>  assertEquals(
<a name="line304"></a>      &#39;AllChildren(div) should continue to match /span&#39;,
<a name="line305"></a>      goog.dom.pattern.MatchType.MATCHING,
<a name="line306"></a>      pattern.matchToken(
<a name="line307"></a>          goog.dom.getElement(&#39;span1&#39;),
<a name="line308"></a>          goog.dom.TagWalkType.END_TAG));
<a name="line309"></a>  assertEquals(
<a name="line310"></a>      &#39;AllChildren(div) should continue to match at /div&#39;,
<a name="line311"></a>      goog.dom.pattern.MatchType.MATCHING,
<a name="line312"></a>      pattern.matchToken(
<a name="line313"></a>          goog.dom.getElement(&#39;div1&#39;),
<a name="line314"></a>          goog.dom.TagWalkType.END_TAG));
<a name="line315"></a>  assertEquals(
<a name="line316"></a>      &#39;AllChildren(div) should finish match at /body&#39;,
<a name="line317"></a>      goog.dom.pattern.MatchType.BACKTRACK_MATCH,
<a name="line318"></a>      pattern.matchToken(
<a name="line319"></a>          document.body,
<a name="line320"></a>          goog.dom.TagWalkType.END_TAG));
<a name="line321"></a>}
<a name="line322"></a>
<a name="line323"></a>function testText() {
<a name="line324"></a>  var pattern = new goog.dom.pattern.Text(&#39;Text&#39;);
<a name="line325"></a>  assertEquals(
<a name="line326"></a>      &#39;Text should match div3/text()&#39;,
<a name="line327"></a>      goog.dom.pattern.MatchType.MATCH,
<a name="line328"></a>      pattern.matchToken(
<a name="line329"></a>          goog.dom.getElement(&#39;div3&#39;).firstChild,
<a name="line330"></a>          goog.dom.TagWalkType.OTHER));
<a name="line331"></a>  assertEquals(
<a name="line332"></a>      &#39;Text should not match div4/text()&#39;,
<a name="line333"></a>      goog.dom.pattern.MatchType.NO_MATCH,
<a name="line334"></a>      pattern.matchToken(
<a name="line335"></a>          goog.dom.getElement(&#39;div4&#39;).firstChild,
<a name="line336"></a>          goog.dom.TagWalkType.OTHER));
<a name="line337"></a>  assertEquals(
<a name="line338"></a>      &#39;Text should not match div3&#39;,
<a name="line339"></a>      goog.dom.pattern.MatchType.NO_MATCH,
<a name="line340"></a>      pattern.matchToken(
<a name="line341"></a>          goog.dom.getElement(&#39;div3&#39;),
<a name="line342"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line343"></a>
<a name="line344"></a>}
<a name="line345"></a>
<a name="line346"></a>function testTextRegex() {
<a name="line347"></a>  var pattern = new goog.dom.pattern.Text(/Text/);
<a name="line348"></a>  assertEquals(
<a name="line349"></a>      &#39;Text(regex) should match div3/text()&#39;,
<a name="line350"></a>      goog.dom.pattern.MatchType.MATCH,
<a name="line351"></a>      pattern.matchToken(
<a name="line352"></a>          goog.dom.getElement(&#39;div3&#39;).firstChild,
<a name="line353"></a>          goog.dom.TagWalkType.OTHER));
<a name="line354"></a>  assertEquals(
<a name="line355"></a>      &#39;Text(regex) should match div4/text()&#39;,
<a name="line356"></a>      goog.dom.pattern.MatchType.MATCH,
<a name="line357"></a>      pattern.matchToken(
<a name="line358"></a>          goog.dom.getElement(&#39;div4&#39;).firstChild,
<a name="line359"></a>          goog.dom.TagWalkType.OTHER));
<a name="line360"></a>}
<a name="line361"></a>
<a name="line362"></a>function testNodeType() {
<a name="line363"></a>  var pattern = new goog.dom.pattern.NodeType(goog.dom.NodeType.COMMENT);
<a name="line364"></a>  assertEquals(&#39;Comment matcher should match a comment&#39;,
<a name="line365"></a>      goog.dom.pattern.MatchType.MATCH,
<a name="line366"></a>      pattern.matchToken(
<a name="line367"></a>          goog.dom.getElement(&#39;nodeTypes&#39;).firstChild,
<a name="line368"></a>          goog.dom.TagWalkType.OTHER));
<a name="line369"></a>  assertEquals(&#39;Comment matcher should not match a text node&#39;,
<a name="line370"></a>      goog.dom.pattern.MatchType.NO_MATCH,
<a name="line371"></a>      pattern.matchToken(
<a name="line372"></a>          goog.dom.getElement(&#39;nodeTypes&#39;).lastChild,
<a name="line373"></a>          goog.dom.TagWalkType.OTHER));
<a name="line374"></a>}
<a name="line375"></a>
<a name="line376"></a>function testSequence() {
<a name="line377"></a>  var pattern = new goog.dom.pattern.Sequence([
<a name="line378"></a>    new goog.dom.pattern.StartTag(&#39;DIV&#39;),
<a name="line379"></a>    new goog.dom.pattern.StartTag(&#39;SPAN&#39;),
<a name="line380"></a>    new goog.dom.pattern.EndTag(&#39;SPAN&#39;),
<a name="line381"></a>    new goog.dom.pattern.EndTag(&#39;DIV&#39;)]);
<a name="line382"></a>
<a name="line383"></a>  assertEquals(
<a name="line384"></a>      &#39;Sequence[0] should match div1&#39;,
<a name="line385"></a>      goog.dom.pattern.MatchType.MATCHING,
<a name="line386"></a>      pattern.matchToken(
<a name="line387"></a>          goog.dom.getElement(&#39;div1&#39;),
<a name="line388"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line389"></a>  assertEquals(
<a name="line390"></a>      &#39;Sequence[1] should match span1&#39;,
<a name="line391"></a>      goog.dom.pattern.MatchType.MATCHING,
<a name="line392"></a>      pattern.matchToken(
<a name="line393"></a>          goog.dom.getElement(&#39;span1&#39;),
<a name="line394"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line395"></a>  assertEquals(
<a name="line396"></a>      &#39;Sequence[2] should match /span1&#39;,
<a name="line397"></a>      goog.dom.pattern.MatchType.MATCHING,
<a name="line398"></a>      pattern.matchToken(
<a name="line399"></a>          goog.dom.getElement(&#39;span1&#39;),
<a name="line400"></a>          goog.dom.TagWalkType.END_TAG));
<a name="line401"></a>  assertEquals(
<a name="line402"></a>      &#39;Sequence[3] should match /div1&#39;,
<a name="line403"></a>      goog.dom.pattern.MatchType.MATCH,
<a name="line404"></a>      pattern.matchToken(
<a name="line405"></a>          goog.dom.getElement(&#39;div1&#39;),
<a name="line406"></a>          goog.dom.TagWalkType.END_TAG));
<a name="line407"></a>
<a name="line408"></a>  assertEquals(
<a name="line409"></a>      &#39;Sequence[0] should match div1 again&#39;,
<a name="line410"></a>      goog.dom.pattern.MatchType.MATCHING,
<a name="line411"></a>      pattern.matchToken(
<a name="line412"></a>          goog.dom.getElement(&#39;div1&#39;),
<a name="line413"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line414"></a>  assertEquals(
<a name="line415"></a>      &#39;Sequence[1] should match span1 again&#39;,
<a name="line416"></a>      goog.dom.pattern.MatchType.MATCHING,
<a name="line417"></a>      pattern.matchToken(
<a name="line418"></a>          goog.dom.getElement(&#39;span1&#39;),
<a name="line419"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line420"></a>  assertEquals(
<a name="line421"></a>      &#39;Sequence[2] should match /span1 again&#39;,
<a name="line422"></a>      goog.dom.pattern.MatchType.MATCHING,
<a name="line423"></a>      pattern.matchToken(
<a name="line424"></a>          goog.dom.getElement(&#39;span1&#39;),
<a name="line425"></a>          goog.dom.TagWalkType.END_TAG));
<a name="line426"></a>  assertEquals(
<a name="line427"></a>      &#39;Sequence[3] should match /div1 again&#39;,
<a name="line428"></a>      goog.dom.pattern.MatchType.MATCH,
<a name="line429"></a>      pattern.matchToken(
<a name="line430"></a>          goog.dom.getElement(&#39;div1&#39;),
<a name="line431"></a>          goog.dom.TagWalkType.END_TAG));
<a name="line432"></a>
<a name="line433"></a>  assertEquals(
<a name="line434"></a>      &#39;Sequence[0] should match div1&#39;,
<a name="line435"></a>      goog.dom.pattern.MatchType.MATCHING,
<a name="line436"></a>      pattern.matchToken(
<a name="line437"></a>          goog.dom.getElement(&#39;div1&#39;),
<a name="line438"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line439"></a>  assertEquals(
<a name="line440"></a>      &#39;Sequence[1] should not match div1&#39;,
<a name="line441"></a>      goog.dom.pattern.MatchType.NO_MATCH,
<a name="line442"></a>      pattern.matchToken(
<a name="line443"></a>          goog.dom.getElement(&#39;div1&#39;),
<a name="line444"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line445"></a>
<a name="line446"></a>  assertEquals(
<a name="line447"></a>      &#39;Sequence[0] should match div1 after failure&#39;,
<a name="line448"></a>      goog.dom.pattern.MatchType.MATCHING,
<a name="line449"></a>      pattern.matchToken(
<a name="line450"></a>          goog.dom.getElement(&#39;div1&#39;),
<a name="line451"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line452"></a>  assertEquals(
<a name="line453"></a>      &#39;Sequence[1] should match span1 after failure&#39;,
<a name="line454"></a>      goog.dom.pattern.MatchType.MATCHING,
<a name="line455"></a>      pattern.matchToken(
<a name="line456"></a>          goog.dom.getElement(&#39;span1&#39;),
<a name="line457"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line458"></a>  assertEquals(
<a name="line459"></a>      &#39;Sequence[2] should match /span1 after failure&#39;,
<a name="line460"></a>      goog.dom.pattern.MatchType.MATCHING,
<a name="line461"></a>      pattern.matchToken(
<a name="line462"></a>          goog.dom.getElement(&#39;span1&#39;),
<a name="line463"></a>          goog.dom.TagWalkType.END_TAG));
<a name="line464"></a>  assertEquals(
<a name="line465"></a>      &#39;Sequence[3] should match /div1 after failure&#39;,
<a name="line466"></a>      goog.dom.pattern.MatchType.MATCH,
<a name="line467"></a>      pattern.matchToken(
<a name="line468"></a>          goog.dom.getElement(&#39;div1&#39;),
<a name="line469"></a>          goog.dom.TagWalkType.END_TAG));
<a name="line470"></a>}
<a name="line471"></a>
<a name="line472"></a>function testRepeat() {
<a name="line473"></a>  var pattern = new goog.dom.pattern.Repeat(
<a name="line474"></a>      new goog.dom.pattern.StartTag(&#39;B&#39;));
<a name="line475"></a>
<a name="line476"></a>  // Note: this test does not mimic an actual matcher because it is only
<a name="line477"></a>  // passing the START_TAG events.
<a name="line478"></a>
<a name="line479"></a>  assertEquals(
<a name="line480"></a>      &#39;Repeat[B] should match b1&#39;,
<a name="line481"></a>      goog.dom.pattern.MatchType.MATCHING,
<a name="line482"></a>      pattern.matchToken(
<a name="line483"></a>          goog.dom.getElement(&#39;b1&#39;),
<a name="line484"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line485"></a>  assertEquals(
<a name="line486"></a>      &#39;Repeat[B] should match b2&#39;,
<a name="line487"></a>      goog.dom.pattern.MatchType.MATCHING,
<a name="line488"></a>      pattern.matchToken(
<a name="line489"></a>          goog.dom.getElement(&#39;b2&#39;),
<a name="line490"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line491"></a>  assertEquals(
<a name="line492"></a>      &#39;Repeat[B] should backtrack match i1&#39;,
<a name="line493"></a>      goog.dom.pattern.MatchType.BACKTRACK_MATCH,
<a name="line494"></a>      pattern.matchToken(
<a name="line495"></a>          goog.dom.getElement(&#39;i1&#39;),
<a name="line496"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line497"></a>  assertEquals(
<a name="line498"></a>      &#39;Repeat[B] should have match count of 2&#39;,
<a name="line499"></a>      2,
<a name="line500"></a>      pattern.count);
<a name="line501"></a>
<a name="line502"></a>  assertEquals(
<a name="line503"></a>      &#39;Repeat[B] should backtrack match i1 even with no b matches&#39;,
<a name="line504"></a>      goog.dom.pattern.MatchType.BACKTRACK_MATCH,
<a name="line505"></a>      pattern.matchToken(
<a name="line506"></a>          goog.dom.getElement(&#39;i1&#39;),
<a name="line507"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line508"></a>  assertEquals(
<a name="line509"></a>      &#39;Repeat[B] should have match count of 0&#39;,
<a name="line510"></a>      0,
<a name="line511"></a>      pattern.count);
<a name="line512"></a>}
<a name="line513"></a>
<a name="line514"></a>function testRepeatWithMinimum() {
<a name="line515"></a>  var pattern = new goog.dom.pattern.Repeat(
<a name="line516"></a>      new goog.dom.pattern.StartTag(&#39;B&#39;), 1);
<a name="line517"></a>
<a name="line518"></a>  // Note: this test does not mimic an actual matcher because it is only
<a name="line519"></a>  // passing the START_TAG events.
<a name="line520"></a>
<a name="line521"></a>  assertEquals(
<a name="line522"></a>      &#39;Repeat[B,1] should match b1&#39;,
<a name="line523"></a>      goog.dom.pattern.MatchType.MATCHING,
<a name="line524"></a>      pattern.matchToken(
<a name="line525"></a>          goog.dom.getElement(&#39;b1&#39;),
<a name="line526"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line527"></a>  assertEquals(
<a name="line528"></a>      &#39;Repeat[B,1] should match b2&#39;,
<a name="line529"></a>      goog.dom.pattern.MatchType.MATCHING,
<a name="line530"></a>      pattern.matchToken(
<a name="line531"></a>          goog.dom.getElement(&#39;b2&#39;),
<a name="line532"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line533"></a>  assertEquals(
<a name="line534"></a>      &#39;Repeat[B,1] should backtrack match i1&#39;,
<a name="line535"></a>      goog.dom.pattern.MatchType.BACKTRACK_MATCH,
<a name="line536"></a>      pattern.matchToken(
<a name="line537"></a>          goog.dom.getElement(&#39;i1&#39;),
<a name="line538"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line539"></a>  assertEquals(
<a name="line540"></a>      &#39;Repeat[B,1] should have match count of 2&#39;,
<a name="line541"></a>      2,
<a name="line542"></a>      pattern.count);
<a name="line543"></a>
<a name="line544"></a>  assertEquals(
<a name="line545"></a>      &#39;Repeat[B,1] should not match i1&#39;,
<a name="line546"></a>      goog.dom.pattern.MatchType.NO_MATCH,
<a name="line547"></a>      pattern.matchToken(
<a name="line548"></a>          goog.dom.getElement(&#39;i1&#39;),
<a name="line549"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line550"></a>}
<a name="line551"></a>
<a name="line552"></a>function testRepeatWithMaximum() {
<a name="line553"></a>  var pattern = new goog.dom.pattern.Repeat(
<a name="line554"></a>      new goog.dom.pattern.StartTag(&#39;B&#39;), 1, 1);
<a name="line555"></a>
<a name="line556"></a>  // Note: this test does not mimic an actual matcher because it is only
<a name="line557"></a>  // passing the START_TAG events.
<a name="line558"></a>
<a name="line559"></a>  assertEquals(
<a name="line560"></a>      &#39;Repeat[B,1] should match b1&#39;,
<a name="line561"></a>      goog.dom.pattern.MatchType.MATCH,
<a name="line562"></a>      pattern.matchToken(
<a name="line563"></a>          goog.dom.getElement(&#39;b1&#39;),
<a name="line564"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line565"></a>}
<a name="line566"></a>
<a name="line567"></a>function testSequenceBacktrack() {
<a name="line568"></a>  var pattern = new goog.dom.pattern.Sequence([
<a name="line569"></a>    new goog.dom.pattern.Repeat(new goog.dom.pattern.StartTag(&#39;SPAN&#39;)),
<a name="line570"></a>    new goog.dom.pattern.Text(&#39;X&#39;)]);
<a name="line571"></a>
<a name="line572"></a>  var root = goog.dom.getElement(&#39;span3&#39;);
<a name="line573"></a>  assertEquals(
<a name="line574"></a>      &#39;Sequence[Repeat[SPAN],&quot;X&quot;] should match span3&#39;,
<a name="line575"></a>      goog.dom.pattern.MatchType.MATCHING,
<a name="line576"></a>      pattern.matchToken(root, goog.dom.TagWalkType.START_TAG));
<a name="line577"></a>  assertEquals(
<a name="line578"></a>      &#39;Sequence[Repeat[SPAN],&quot;X&quot;] should match span3.firstChild&#39;,
<a name="line579"></a>      goog.dom.pattern.MatchType.MATCHING,
<a name="line580"></a>      pattern.matchToken(root.firstChild,
<a name="line581"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line582"></a>  assertEquals(
<a name="line583"></a>      &#39;Sequence[Repeat[SPAN],&quot;X&quot;] should match span3.firstChild.firstChild&#39;,
<a name="line584"></a>      goog.dom.pattern.MatchType.MATCHING,
<a name="line585"></a>      pattern.matchToken(root.firstChild.firstChild,
<a name="line586"></a>          goog.dom.TagWalkType.START_TAG));
<a name="line587"></a>  assertEquals(
<a name="line588"></a>      &#39;Sequence[Repeat[SPAN],&quot;X&quot;] should finish match text node&#39;,
<a name="line589"></a>      goog.dom.pattern.MatchType.MATCH,
<a name="line590"></a>      pattern.matchToken(root.firstChild.firstChild.firstChild,
<a name="line591"></a>          goog.dom.TagWalkType.OTHER));
<a name="line592"></a>}
</pre>


</body>
</html>
